# coding: utf-8
from sqlalchemy import Column, DECIMAL, Index, String, TIMESTAMP, Text, text, Float, Date, DateTime, JSON
from sqlalchemy.dialects.mysql import BIGINT, INTEGER, LONGTEXT, TINYINT, VARCHAR
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class Admin(Base):
    __tablename__ = 'admin'

    id = Column(INTEGER(10), primary_key=True, comment='主键id')
    userName = Column(VARCHAR(50), nullable=False, comment='管理员账号')
    password = Column(VARCHAR(50), nullable=False, comment='密码')
    salt = Column(VARCHAR(50), nullable=False, comment='盐')
    bid = Column(VARCHAR(50), nullable=False, comment='加密之后的账号')
    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

class BusinessInfo(Base):
    __tablename__ = 'business_info'

    id = Column(INTEGER(11), primary_key=True)
    shopId = Column(String(20), comment='店铺的shopid')
    type = Column(INTEGER(1), comment='店铺的类型，当前知识美团使用')
    day = Column(Date, comment='哪一天的数据')
    exposureNum = Column(INTEGER(11), comment='每天的曝光数目')
    clickNum = Column(INTEGER(11), comment='每天的访问数')
    cost = Column(Float(7, True), comment='每天的推广花费')
    avgPrice = Column(Float(5, True), comment='每天单词点击花费')
    orderNum = Column(INTEGER(11), comment='每天下单人数')
    visitRate = Column(Float(5, True), comment='入店转换率')
    orderRate = Column(Float(5, True), comment='下单转换率')
    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

class DaysDatum(Base):
    __tablename__ = 'days_data'

    id = Column(INTEGER(12), primary_key=True)
    shopId = Column(BIGINT(20))
    shopType = Column(INTEGER(2))
    day = Column(String(12))
    targetExposure = Column(INTEGER(10))
    budget = Column(DECIMAL(10, 2))
    historyCurbid = Column(String(1024))
    maxPrice = Column(DECIMAL(10, 2))
    minPrice = Column(DECIMAL(10, 2))
    shopName = Column(String(255))
    busyMaxPrice = Column(DECIMAL(10, 2))
    busyMinPrice = Column(DECIMAL(10, 2))
    idleMaxPrice = Column(DECIMAL(10, 2))
    idleMinPrice = Column(DECIMAL(10, 2))
class ShopBidding(Base):
    __tablename__ = 'shop_bidding'
    __table_args__ = (
        Index('aliyun_id_time_type', 'shopid', 'biddingTime', 'shoptype'),
    )

    id = Column(INTEGER(11), primary_key=True)
    shopid = Column(INTEGER(11))
    biddingTime = Column(String(64))
    targetNum = Column(DECIMAL(10, 2), comment='目标爆光数')
    exposureNum = Column(DECIMAL(10, 2), comment='当前爆光数')
    replenishNum = Column(DECIMAL(10, 2), comment='补偿曝光数')
    basePrice = Column(DECIMAL(10, 2), comment='当前基础出价')
    directPrice = Column(DECIMAL(10, 2), comment='定向出价')
    log = Column(String(1024), comment='操作记录')
    blance = Column(DECIMAL(10, 2), comment='余额')
    shoptype = Column(INTEGER(11), comment='1、美团')
    status = Column(INTEGER(1), server_default=text("'0'"))
    isbybudget = Column(INTEGER(11), server_default=text("'0'"), comment='按预算推广')
    createtime = Column(String(64))
    visitNum = Column(INTEGER(11))
    exLog = Column(String(1024))
    todayBudget = Column(DECIMAL(10, 2))
    periodtarget = Column(DECIMAL(10, 2))
    periodexposure = Column(DECIMAL(10, 2))
    businessAmount = Column(DECIMAL(10, 2))
    allExposure = Column(DECIMAL(10, 2))
    realTimeOrder = Column(DECIMAL(10, 2))
    percentBudget = Column(DECIMAL(10, 4))
    currentCost = Column(DECIMAL(10, 2))
    setPrice = Column(DECIMAL(10, 2))
    shopStatus = Column(TINYINT(2), comment='店铺状态，1正常营业，0非正常营业')
    avgPrice = Column(DECIMAL(5, 2), server_default=text("'0.00'"), comment='每天的平均出价')
    daysAvgPrice = Column(DECIMAL(5, 2), server_default=text("'0.00'"), comment='每天的平均出价')
    daysAvgClickCount = Column(DECIMAL(8, 2), server_default=text("'0.00'"), comment='每天的平均出价')


class Report(Base):
    __tablename__ = 'report'

    id = Column(INTEGER(11), primary_key=True)
    shopId = Column(BIGINT(20))
    shopType = Column(INTEGER(2))
    date = Column(VARCHAR(64))
    newSingle = Column(INTEGER(11))
    oldSingle = Column(INTEGER(11))
    newPercent = Column(Float(11))
    oldPercent = Column(Float(11))
    exposureNum = Column(INTEGER(11))
    visitNum = Column(INTEGER(11))
    orderNum = Column(INTEGER(11))
    visitRate = Column(Float(11))
    orderRate = Column(Float(11))
    score = Column(Float(11))
    bizListExposureNum = Column(INTEGER(11))
    otherExposureNum = Column(INTEGER(11))
    searchExposureNum = Column(INTEGER(11))
    orderPageExposureNum = Column(INTEGER(11))
    selectForUExposureNum = Column(INTEGER(11))
    commentStarInfo = Column(VARCHAR(256))
    activity = Column(LONGTEXT)
    comment = Column(LONGTEXT)
    cost = Column(Float(11))
    settleAcc = Column(Float(11))
    peerExposureNum = Column(INTEGER(11))
    peerVisitRate = Column(Float(11))
    peerOrderRate = Column(Float(11))
    peerSearchExposureNum = Column(INTEGER(11))
    peerBizListExposureNum = Column(INTEGER(11))
    peerOrderPageExposureNum = Column(INTEGER(11))
    peerSelectForUExposureNum = Column(INTEGER(11))
    peerOtherExposureNum = Column(INTEGER(11))
    effectiveOrders = Column(INTEGER(11))
    allRepeat = Column(INTEGER(11))
    allRepeatRate = Column(Float(11))
    allRepeatCompareLastWeek = Column(Float(11))
    allRepeatCompareLastMonth = Column(Float(11))
    newRepeat = Column(INTEGER(11))
    newRepeatRate = Column(Float(11))
    newRepeatCompareLastWeek = Column(Float(11))
    newRepeatCompareLastMonth = Column(Float(11))
    oldRepeat = Column(INTEGER(11))
    oldRepeatRate = Column(Float(11))
    oldRepeatCompareLastWeek = Column(Float(11))
    oldRepeatCompareLastMonth = Column(Float(11))
    label1 = Column(INTEGER(11))
    label2 = Column(INTEGER(11))

class ShopBiddingTarget(Base):
    __tablename__ = 'shop_bidding_target'
    __table_args__ = (
        Index('account', 'account', 'exposureTime', 'type', unique=True),
    )

    id = Column(INTEGER(11), primary_key=True)
    shopid = Column(INTEGER(11))
    account = Column(String(64), comment='账号（美团、饿了么）')
    exposureNum = Column(DECIMAL(10, 2), comment='爆光目标值 ')
    exposureTime = Column(String(64), comment='爆光时间')
    type = Column(INTEGER(11), comment='1、mt,2，ele')
    isbybudget = Column(INTEGER(11), server_default=text("'0'"), comment='按预算推广')
    newExposureNum = Column(INTEGER(11))
    periodtarget = Column(INTEGER(11))
    budget = Column(DECIMAL(10, 2))


class ShopEleInfo(Base):
    __tablename__ = 'shop_ele_info'

    id = Column(INTEGER(11), primary_key=True)
    shopType = Column(TINYINT(4), comment='1、美团，2、饿了么')
    eleId = Column(BIGINT(20), unique=True, comment='饿了么ID')
    account = Column(String(64))
    eleName = Column(String(255), comment='饿了么店铺名称')
    shopTimeStart = Column(String(64), comment='营业时间')
    shopTimeEnd = Column(String(64), comment='营业结束时间')
    shipTime = Column(String(1024), comment='营业时间段')
    percent = Column(String(200), comment='订单的比例')
    adTime = Column(String(1024), comment='推广时间段')
    shopStatus = Column(TINYINT(4), comment='店铺状态1、营业，2、休息')
    cookies = Column(Text, comment='cookie')
    budget = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='预算')
    isenable = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否启用竞价')
    isonline = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否在线')
    createtime = Column(String(64))
    updatetime = Column(String(64))
    deleted = Column(INTEGER(11), nullable=False, server_default=text("'0'"))
    targetExposure = Column(INTEGER(11), comment='目标爆光次数')
    isbind = Column(INTEGER(11))
    isbybudget = Column(INTEGER(11), server_default=text("'0'"), comment='按预算推广')
    specialtime = Column(String(2048))
    keepSameStatus = Column(INTEGER(11))
    userName = Column(String(40))
    isremake = Column(INTEGER(2), server_default=text("'0'"), comment='是否需要重新计算')
    salt = Column(String(30))
    shopId = Column(String(40))
    serviceTime = Column(String(1024))
    guard = Column(TINYINT(1), server_default=text("'0'"), comment='是否开启监测系统')
    historyCurbid = Column(String(1024))
    plan = Column(String(1024))
    orderRate = Column(String(1024))
    busyTimeLock = Column(INTEGER(11))
    exposureRate = Column(String(255))
    result = Column(String(255), comment='效果对比')

class ShopEleInfoCopy(Base):
    __tablename__ = 'shop_ele_info_copy'

    id = Column(INTEGER(11), primary_key=True)
    shopType = Column(TINYINT(4), comment='1、美团，2、饿了么')
    eleId = Column(BIGINT(20), unique=True, comment='饿了么ID')
    account = Column(String(64))
    eleName = Column(String(255), comment='饿了么店铺名称')
    shopTimeStart = Column(String(64), comment='营业时间')
    shopTimeEnd = Column(String(64), comment='营业结束时间')
    shipTime = Column(String(1024), comment='营业时间段')
    percent = Column(String(200), comment='订单的比例')
    adTime = Column(String(1024), comment='推广时间段')
    isremake = Column(INTEGER(2), server_default=text("'0'"), comment='是否需要重新计算')
    shopStatus = Column(TINYINT(4), comment='店铺状态1、营业，2、休息')
    cookies = Column(Text, comment='cookie')
    budget = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='预算')
    isenable = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否启用竞价')
    isonline = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否在线')
    createtime = Column(String(64))
    updatetime = Column(String(64))
    deleted = Column(INTEGER(11), nullable=False, server_default=text("'0'"))
    targetExposure = Column(INTEGER(11), comment='目标爆光次数')
    isbind = Column(INTEGER(11))
    isbybudget = Column(INTEGER(11), server_default=text("'0'"), comment='按预算推广')
    specialtime = Column(String(2048))
    keepSameStatus = Column(INTEGER(11))
    userName = Column(String(40))
    salt = Column(String(30))
    shopId = Column(String(40))
    serviceTime = Column(String(1024))
    guard = Column(TINYINT(1), server_default=text("'0'"), comment='是否开启监测系统')
    historyCurbid = Column(String(1024))


class ShopException(Base):
    __tablename__ = 'shop_exception'

    id = Column(INTEGER(11), primary_key=True)
    shopId = Column(VARCHAR(40), nullable=False)
    log = Column(VARCHAR(255))
    shopType = Column(TINYINT(1))
    isDeal = Column(TINYINT(1))
    createTime = Column(TIMESTAMP)
    updateTime = Column(TIMESTAMP)


class ShopInfo(Base):
    __tablename__ = 'shop_info'

    id = Column(INTEGER(11), primary_key=True)
    shopType = Column(TINYINT(4), unique=True, comment='1、美团，2、饿了么')
    shopName = Column(String(255), comment='店铺名称')
    maxprice = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='最高出价')
    minprice = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='最低出价')
    reduceprice = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='减价幅度')
    increaseprice = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='增加幅度')
    directStartPrice = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='定向开始价格')
    directEndPrice = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='定向结束价格')
    updatetime = Column(String(64))
    createtime = Column(String(64))
    deleted = Column(INTEGER(11), nullable=False, server_default=text("'0'"))
    mtId = Column(INTEGER(11))
    eleId = Column(INTEGER(11))
    mtaccount = Column(String(64))
    eleaccount = Column(String(64))
    targetExposure = Column(INTEGER(11), comment='爆光目标次数')
    budget = Column(DECIMAL(10, 0), server_default=text("'0'"))

class IpPool(Base):
    __tablename__ = 'ip_pool'
    id = Column(INTEGER(11), primary_key=True)
    ip = Column(VARCHAR(50), comment='ip地址')
    valid = Column(TINYINT(1), server_default=text("'0'"), comment='1有效，2失效，3备用')
    invalidnum = Column(INTEGER(5), server_default=text("'0'"), comment='某段时间内ip失效次数')
    shopnum = Column(INTEGER(4), server_default=text("'0'"), comment='当前ip服务的店铺数量')


class ShopMeituanInfo(Base):
    __tablename__ = 'shop_meituan_info'
    id = Column(INTEGER(11), primary_key=True)
    shopType = Column(TINYINT(4), comment='1、美团，2、饿了么')
    mtId = Column(BIGINT(20), index=True, comment='饿了么ID')
    account = Column(String(64))
    mtName = Column(String(255), comment='饿了么店铺名称')
    shopTimeStart = Column(String(64), comment='营业时间')
    shopTimeEnd = Column(String(64), comment='营业结束时间')
    shipTime = Column(String(1024), comment='营业时间段')
    adTime = Column(String(1024), comment='推广时间段')
    percent = Column(String(200), comment='比例数组')
    shopStatus = Column(TINYINT(4), comment='店铺状态1、营业，2、休息')
    cookies = Column(Text, comment='cookie')
    budget = Column(DECIMAL(10, 2), server_default=text("'0.00'"), comment='预算')
    isenable = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否启用竞价')
    isonline = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否在线')
    createtime = Column(String(64))
    updatetime = Column(String(64))
    deleted = Column(INTEGER(11), server_default=text("'0'"))
    targetExposure = Column(INTEGER(11), server_default=text("'0'"), comment='目标爆光次数')
    isbind = Column(INTEGER(11))
    isbybudget = Column(INTEGER(11), server_default=text("'0'"), comment='按预算推广')
    isremake = Column(INTEGER(2), server_default=text("'0'"), comment='是否需要重新计算')
    specialtime = Column(String(2048))
    userName = Column(String(40))
    salt = Column(String(30))
    shopId = Column(String(40))
    keepSameStatus = Column(INTEGER(11))
    serviceTime = Column(String(1024))
    guard = Column(TINYINT(1), server_default=text("'0'"), comment='是否开启监测系统')
    historyCurbid = Column(String(1024))
    plan = Column(String(1024))
    ip = Column(String(200))
    orderRate = Column(String(1024))

    busyTimeLock = Column(INTEGER(11))
    exposureRate = Column(String(255))
    result = Column(String(255), comment='效果对比')
class ShopOrder(Base):
    __tablename__ = 'shop_order'

    id = Column(INTEGER(11), primary_key=True)
    shopid = Column(INTEGER(11))
    ordernum = Column(INTEGER(11))
    ordertime = Column(INTEGER(11))
    proportion = Column(DECIMAL(10, 2), comment='比例')


class ShopSpiderLog(Base):
    __tablename__ = 'shop_spider_log'

    id = Column(INTEGER(11), primary_key=True)
    shopid = Column(INTEGER(11))


class SuggestParam(Base):
    __tablename__ = 'suggest_param'

    id = Column(INTEGER(11), primary_key=True)
    shopId = Column(BIGINT(20), comment='店铺的id')
    shopType = Column(TINYINT(1), comment='店铺的种类')
    day = Column(String(50), comment='记录的创建时间')
    maxPrice = Column(DECIMAL(7, 1), comment='最高出价')
    sevenAvgPrice = Column(DECIMAL(7, 2), comment='七天平均的出价')
    minPrice = Column(DECIMAL(3, 1), comment='最低价')
    budget = Column(DECIMAL(7, 2), comment='预算')
    sevenAvgIncome = Column(DECIMAL(9, 2), comment='七天的平均收入')
    targetExposure = Column(INTEGER(6), comment='预期曝光值')
    allExposure = Column(INTEGER(6), comment='总曝光，美团是七天的，饿了么是一天的')
    allCost = Column(DECIMAL(7, 2), comment='总花费，美团是七天的花费，饿了么是一天的花费')
    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

class User(Base):
    __tablename__ = 'user'

    id = Column(INTEGER(11), primary_key=True)
    username = Column(String(255))
    password = Column(String(255))
    salt = Column(BIGINT(20))
    realname = Column(String(255))
    phone = Column(String(20))
    openId = Column(String(128), comment='第三方登录')
    ispay = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='是否会员')
    expiretime = Column(BIGINT(20), server_default=text("'0'"), comment='会员过期时间')
    createtime = Column(String(64))
    updatetime = Column(String(64))
    deleted = Column(TINYINT(4), server_default=text("'0'"))


class UserInvitationPayDetail(Base):
    __tablename__ = 'user_invitation_pay_detail'

    id = Column(INTEGER(11), primary_key=True)
    userId = Column(INTEGER(11))
    pay_no = Column(String(128), comment='交易订单号')
    slaveid = Column(INTEGER(11), comment='被邀请者ID')
    addtype = Column(INTEGER(11), comment='增加类型1、邀请好友，2、支付')
    adddays = Column(BIGINT(20), comment='增加天数')
    createtime = Column(String(64))


class UserShopRelation(Base):
    __tablename__ = 'user_shop_relation'

    id = Column(INTEGER(11), primary_key=True)
    userId = Column(INTEGER(11))
    shopId = Column(INTEGER(11))
    isbind = Column(INTEGER(11), nullable=False, server_default=text("'1'"), comment='是否关联')
    createtime = Column(String(64))
    updatetime = Column(String(64))


class YesOrderInfo(Base):
    __tablename__ = 'yes_order_info'

    id = Column(INTEGER(11), primary_key=True)
    account = Column(String(255))
    day = Column(String(255))
    InfoList = Column(LONGTEXT)
    updatetime = Column(String(255))
    orderDetail = Column(LONGTEXT)
    note = Column(Text, comment='店铺的日志')
    headInfo = Column(String(200))
    priceCount = Column(String(1024))

class YesOrderInfo1(Base):
    __tablename__ = 'yes_order_info1'

    id = Column(INTEGER(11), primary_key=True)
    account = Column(String(255))
    day = Column(String(255))
    InfoList = Column(LONGTEXT)
    updatetime = Column(String(255))

class OperationDaily(Base):
    __tablename__ = 'operation_daily'
    __table_args__ = (
        Index('shopid_day_type', 'shopId', 'type', 'day'),
    )

    id = Column(INTEGER(11), primary_key=True)
    shopId = Column(String(20), comment='店铺的shopid')
    type = Column(INTEGER(1), comment='店铺的类型')
    day = Column(Date, comment='哪一天的数据')
    createTime = Column(DateTime, comment='记录的产生时间')
    params = Column(String(512), comment='当前接口的所有参数')
    errorLog = Column(String(255), comment='接口错误日志')
    account = Column(String(64), comment='操作账号')
    apiName = Column(String(64), comment='当前接口名称')
    remark = Column(String(255), comment='备注信息')
    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

class Research(Base):
    __tablename__ = 'research'
    id = Column(INTEGER(10), primary_key=True)
    user_id = Column(INTEGER(10), nullable=False)
    food_ids = Column(LONGTEXT, nullable=True)
    same_sale_ids = Column(LONGTEXT, nullable=True)
    same_distance_ids = Column(LONGTEXT, nullable=True)
    location_xy = Column(VARCHAR(255), nullable=False)
    location_name = Column(VARCHAR(255), nullable=False)
    num = Column(INTEGER(2), nullable=False)
    outline = Column(JSON(0), nullable=True)
    detail = Column(JSON(0), nullable=True)
    category_name = Column(VARCHAR(255), nullable=False)
    category_code = Column(INTEGER(10), nullable=False)
    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

class AdminShop(Base):
    __tablename__ = 'admin_shop'

    id = Column(INTEGER(5), primary_key=True)
    admin_id = Column(INTEGER(5), nullable=False)
    shop_id = Column(INTEGER(5), nullable=False)
    shop_type = Column(INTEGER(2), nullable=False)
    is_delete = Column(INTEGER(2), nullable=False, server_default=text("'0'"))
    create_time = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))